<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>

<body>
    <div id="app">


        <input type="text" v-model="firstName">+
        <input type="text" v-model="lastName">=
        <input type="text" v-model="fullName">

    </div>
    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                firstName: '',
                lastName: '',
                fullName: ''
            },
            methods: {},
            watch: { // 使用这个属性可以监视 data 中指定数据的变化,然后出发这个 watch 对应的 function 处理函数
                'firstName': function (newVal, oldVal) {
                    //console.log('监视到了firstName的变化')
                    // this.fullName = this.firstName + '-' + this.lastName
                    //console.log(newVal + '---' + oldVal)
                    this.fullName = newVal + '---' + this.lastName
                },
                'lastName': function (newVal) {
                    this.fullName = this.firstName + '---' + newVal
                }
            }
        });
    </script>
</body>

</html>